package com.zjb.chuangxiang.fadingbar;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    private MyScrollView mScrollView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final View relaTitle = findViewById(R.id.relaTitle);
        final View relaHeader = findViewById(R.id.relaHeader);
        relaTitle.getBackground().mutate().setAlpha(0);
        mScrollView = (MyScrollView) findViewById(R.id.scrollView);
        mScrollView.setOnScrollListener(new MyScrollView.OnScrollListener() {
            @Override
            public void onScroll(int scrollY) {
                Log.e("MainActivity", "MainActivity--onScroll--scrollY  "+scrollY);
                if (scrollY<=relaHeader.getHeight() - relaTitle.getHeight()){
                    int i = (int) ((double)scrollY / (double) (relaHeader.getHeight() - relaTitle.getHeight())*255);
                    Log.e("MainActivity", "MainActivity--onScroll--就看看  "+i);
                    relaTitle.getBackground().mutate().setAlpha(i);
                }else {
                    relaTitle.getBackground().mutate().setAlpha(255);
                }
            }
        });
    }

}
